package com.erp.app.catalog.login.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Arrays;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.catalogLogin.pk.CategoryItemLinePk;

import com.erp.app.common.ProjectConstants;

import com.erp.framework.SimpleConstants;

import com.erp.framework.model.pk.SimpleBasePk;

import com.erp.framework.util.CommonUtil;

import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

import com.erp.framework.controller.action.SimpleSearchStyleActionTemplate;
import com.erp.framework.exceptions.FindRecordException;

import com.erp.app.catalog.itemMaster.criteria.ItemMasterCriteria;
import com.erp.app.catalog.itemMaster.criteria.ItemMasterDtlCriteria;
import com.erp.app.catalog.itemMaster.criteria.ItemMasterPicCriteria;
import com.erp.app.catalog.itemMaster.criteria.ItemMasterPriceCriteria;
import com.erp.app.catalog.itemMaster.criteria.ItemMasterRelateItemCriteria;

import com.erp.app.catalog.itemMaster.delegate.ItemMasterGroupCommonDelegate;
import com.erp.app.catalog.itemMaster.vo.ItemMasterDtlVO;
import com.erp.app.catalog.itemMaster.vo.ItemMasterPicVO;
import com.erp.app.catalog.itemMaster.vo.ItemMasterPriceVO;
import com.erp.app.catalog.itemMaster.vo.ItemMasterRelateItemVO;
import com.erp.app.catalog.itemMaster.vo.ItemMasterVO;

import com.erp.app.catalog.category.criteria.CategoryItemCategoryCriteria;
import com.erp.app.catalog.category.criteria.CategoryItemClassCriteria;
import com.erp.app.catalog.category.criteria.CategoryItemLineCriteria;
import com.erp.app.catalog.category.delegate.CategoryCommonDelegate;
import com.erp.app.catalog.category.vo.CategoryItemCategoryVO;
import com.erp.app.catalog.category.vo.CategoryItemClassVO;
import com.erp.app.catalog.category.vo.CategoryItemLineVO;
import com.erp.app.catalog.catgroup.delegate.CatalogGroupCommonDelegate;
import com.erp.app.catalog.catgroup.criteria.CatalogGroupCriteria;
import com.erp.app.util.web.WebUtil;


public final class CatalogLoginAction extends SimpleSearchStyleActionTemplate {
	public static final int MAX_SHOW_PAGE = 20;

	public static final String SHOW_ITEM_LIST_VIEW = "LIST";
	public static final String SHOW_ITEM_DETAIL_VIEW = "DETAIL";
	public static final String SHOW_ITEM_PIC_DETAIL = "PIC_DETAIL";
	public static final String SHOW_MAIN_SEARCH_EXTRA = "SEARCH_EXTRA";
	public static final String SHOW_MAIN_ADVANCE_SEARCH = "ADVANCE_SEARCH";
	
	public static final String ACTION_SCROLL_LEFT = "scrollLeft";
	public static final String ACTION_SCROLL_RIGHT = "scrollRight";
	public static final String ACTION_TO_PAGE = "toPage";
	public static final String ACTION_SEND_EMAIL = "itemSendEmail";
	public static final String ACTION_SHOW_PIC = "showPic";
	public static final String ACTION_SEARCH_EXTRA = "searchExtra";
	public static final String ACTION_ADVANCE_SEARCH = "advanceSearch";
	public static final String ACTION_CHANGE_RESULT_VIEW = "changeResultView";
	public static final String ACTION_ITEM_PIC_DETAIL = "picDetail";
	public static final String ACTION_ITEM_PARENT_PIC_DETAIL = "parentPicDetail";
	public static final String ACTION_ITEM_CHILD_PIC_DETAIL = "childPicDetail";
	public static final String ACTION_SIDEBAR_EXPAND = "sidebarExpand";

	protected String getModuleName(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response){
		return "MOD_CATEGORY_ITEM_LINE";
	}

    protected String getFunctionId(){
		return "catalogLogin.do";
	}
       
    protected String getMasterFormSessionName(){
		return "catalogLoginForm";
	}
        
    protected Class getMasterFormClass(){    	
		return CatalogLoginForm.class;
	}
    
    protected Class getMasterVOClass(){    	
		return CategoryItemLineVO.class;
	}
    
    protected Class getSearchCriteriaClass(){    	
		return CategoryItemLineCriteria.class;
	}
        
    protected void setOtherCriteria(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors, Object criteria){
	}
    
    protected SimpleBasePk getPk(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors){
		
		CategoryItemLinePk pk = null;
//		edit the following with appropriate form field names
//		pk = new CategoryItemLinePk(form.getSrchCompanyCode(), form.getEditCategoryItemLineCode());

		return pk;
	}

    protected void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors){
	}

	protected void initAction(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
        super.initAction(mapping, formIn, request, response, errors);
        HttpSession session = request.getSession(false);   
		CatalogLoginForm form = (CatalogLoginForm) formIn;        
        ActionForward actionForward = new ActionForward(mapping.getInput());
    }

	protected void initForm(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
        super.initForm(mapping, formIn, request, response, errors);
        HttpSession session = request.getSession(false);
        CatalogLoginForm form = (CatalogLoginForm) formIn;        
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(SimpleConstants.SESSION_USER);
		
        ArrayList itemClassVos = new ArrayList();
        ArrayList itemCategoryVos = new ArrayList();
        ArrayList itemLineVos = new ArrayList();
		try{
			CategoryCommonDelegate ccDlg = new CategoryCommonDelegate();										
			
			itemLineVos = ccDlg.findByCriteria(new CategoryItemLineCriteria(null
						, SimpleConstants.GENERIC_ACTIVE,SimpleConstants.GENERIC_YES, editingUser.getUserId()));
			itemCategoryVos = ccDlg.findByCriteria(new CategoryItemCategoryCriteria(null,null
					    , SimpleConstants.GENERIC_ACTIVE,SimpleConstants.GENERIC_YES, editingUser.getUserId()));
			itemClassVos = ccDlg.findByCriteria(new CategoryItemClassCriteria(null,null,null
					     , SimpleConstants.GENERIC_ACTIVE,SimpleConstants.GENERIC_YES, editingUser.getUserId()));							
						
			for(int i=0; !CommonUtil.isEmpty(itemLineVos) && i<itemLineVos.size(); i++){
				CategoryItemLineVO itemLineVO = (CategoryItemLineVO)itemLineVos.get(i);
				
				ArrayList subItemCategoryVOs = new ArrayList();
				for(int j=0; !CommonUtil.isEmpty(itemCategoryVos) && j<itemCategoryVos.size();j++){
					CategoryItemCategoryVO itemCategoryVO = (CategoryItemCategoryVO)itemCategoryVos.get(j);
					
					if (itemLineVO.getItemLine().equals(itemCategoryVO.getItemLine())){
						
						ArrayList subItemClassVOs = new ArrayList();
						for(int k=0; !CommonUtil.isEmpty(itemClassVos) && k<itemClassVos.size();k++){
							CategoryItemClassVO itemClassVO = (CategoryItemClassVO)itemClassVos.get(k);
							
							if (itemCategoryVO.getItemLine().equals(itemClassVO.getItemLine()) 
								&& itemCategoryVO.getItemCategory().equals(itemClassVO.getItemCategory())){
								subItemClassVOs.add(itemClassVO);
							}
						}
						itemCategoryVO.setItemClassVos(subItemClassVOs);						
						
						subItemCategoryVOs.add(itemCategoryVO);
					}
				}
				itemLineVO.setItemCategoryVos(subItemCategoryVOs);
			}			
		}catch(Exception e){
			Logger.logExceptions(this, e);
		}finally{

			form.setCategoryItemLineVos(itemLineVos);			
		}
		
		ArrayList rsltList = new ArrayList();
		// Add by Sunny 2007-06-07 Start
		try{			
			CatalogGroupCommonDelegate cgDlg = new CatalogGroupCommonDelegate();
			CatalogGroupCriteria criteria = new CatalogGroupCriteria();
			criteria.setUserId(editingUser.getUserId());
			rsltList = cgDlg.findByCriteria(criteria);
			form.setCateMenuList(rsltList);
		}catch(Exception e){
			Logger.logExceptions(this, e);
		}
		// Add by Sunny 2007-06-07 End
		
		File file = new File(request.getRealPath("/") + "\\images\\catalogProductImages\\not_found.jpg");
		
		
		
    }



	public ActionForward processActionAdvanceSearch(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		HttpSession session = request.getSession(false);
		ActionForward actionForward = new ActionForward(mapping.getInput());
		
		form.setPageEventSrc(null);
		
		form.setSrchArticleNo(null);
		form.setSrchDesc(null);	

		form.setPageHeaderMainCat(null);
		
		form.setSrchSubCat(null);
		form.setSrchSubCatDtl(null);
		
		form.setMainShowType(SHOW_MAIN_ADVANCE_SEARCH);
		
		return actionForward;
	}

	public void processActionShowAttachPic(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		
		HttpSession session = request.getSession(false);
		CatalogLoginForm form = (CatalogLoginForm) formIn;
		ActionForward actionForward = new ActionForward(mapping.getInput());
		OutputStream out = null;
				
//		int idx = Integer.parseInt(form.getPageEventSrc());
		int idx = Integer.parseInt(CommonUtil.nullToString(request.getParameter("pageEventSrc")));
		ItemMasterVO item = (ItemMasterVO)form.getItemMasterVos().get(idx);
			
		if(!CommonUtil.isEmpty(item.getAttachment())){
			try {
				out = response.getOutputStream();
				
				response.setContentType("image/pjpeg");
				response.setStatus(response.SC_OK);		    
		    		    	
				out.write(item.getAttachment());
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
		Logger.log("idx : "+form.getPageEventSrc());
		Logger.log("item : "+item.getFabricCode());
		Logger.log("processActionShowAttachPic");
	}
	
	public void processActionShowDtlAttachPic(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		
		HttpSession session = request.getSession(false);
		CatalogLoginForm form = (CatalogLoginForm) formIn;
		ActionForward actionForward = new ActionForward(mapping.getInput());
		OutputStream out = null;	
		
		int  idx = form.getCurrPicIdx();
		ItemMasterPicVO itemPic = (ItemMasterPicVO)form.getItemMasterVO().getItemPicVO().get(idx);
				
		if(!CommonUtil.isEmpty(itemPic.getLv2Attachment())){
			response.setContentType("image/pjpeg");
			response.setStatus(response.SC_OK);
			
		    try {
		    	out = response.getOutputStream();	    	
				out.write(itemPic.getLv2Attachment());
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
	
	public ActionForward processActionSearchExtra(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		HttpSession session = request.getSession(false);
		ActionForward actionForward = new ActionForward(mapping.getInput());
		User user = (User) session.getAttribute(SimpleConstants.SESSION_USER);
		String action = form.getAction();
		String evt = form.getPageEvent();
		String evtSrc = form.getPageEventSrc();
		
		ItemMasterGroupCommonDelegate imDlg = new ItemMasterGroupCommonDelegate();		
		
		StringBuffer subNodeIdList = new StringBuffer();
		
		String artNo = "";
		String schDesc = "";		
		String nodeId = new String();		
		
		if (CommonUtil.isEmpty(evtSrc)){
			
		}else if ("headerSearch".equals(evtSrc)){			
			if(!CommonUtil.isEmpty(form.getPageHeaderMainCat())) {
				subNodeIdList.append(CommonUtil.isEmpty(subNodeIdList)?"":",");
				subNodeIdList.append("'"+form.getPageHeaderMainCat()+"'");
			}
			schDesc = CommonUtil.isEmpty(form.getSrchDesc())?"":form.getSrchDesc();
		}else if ("advanceSearch".equals(evtSrc)){			
			for(int i=0; form.getSrchSubCatDtl()!=null && i<form.getSrchSubCatDtl().length; i++){
				subNodeIdList.append(CommonUtil.isEmpty(subNodeIdList)?"":",");
				subNodeIdList.append("'"+form.getSrchSubCatDtl()[i]+"'");
			}
			if(!CommonUtil.isEmpty(form.getSrchMainCat())) {
				subNodeIdList.append(CommonUtil.isEmpty(subNodeIdList)?"":",");
				subNodeIdList.append("'"+form.getSrchMainCat()+"'");
			}
			schDesc = form.getSrchArticleNo();
		}else{
			subNodeIdList.append("'"+evtSrc+"'");//search from siber
		}
		
		ArrayList itemList = new ArrayList();
		try{						
			itemList = getItemList(new ItemMasterCriteria(WebUtil.getAppropriateCompanyCode(session,null)
														, subNodeIdList.toString()
														, schDesc
														, user.getUserId()));			
		}catch(Exception e){
			Logger.logExceptions(this, e);
		}
	
		form.setItemMasterVos(itemList);
		form.setTtlPage((int)Math.ceil(itemList.size()*1.0/MAX_SHOW_PAGE));

		form.setSidx(0);
		form.setMainShowType(SHOW_MAIN_SEARCH_EXTRA);
		form.setShowType(SHOW_ITEM_LIST_VIEW);
		
		form.setPageEventSrc(null);
		
		form.setSrchArticleNo(null);
		form.setSrchDesc(null);
		
		form.setSrchMainCat(null);
		form.setPageHeaderMainCat(null);
		
		form.setSrchSubCat(null);
		form.setSrchSubCatDtl(null);		

		return actionForward;
	}

	public ActionForward processActionChangeResultView(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		HttpSession session = request.getSession(false);
		ActionForward actionForward = new ActionForward(mapping.getInput());
	
		String evtSrc = form.getPageEventSrc();		
		form.setSidx(0);
		form.setShowType(evtSrc);
		form.setPageEventSrc(null);
		return actionForward;
	}
	
	public ActionForward processActionParentPicDetail(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {		
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		form.setItemMasterVos(form.getParentItemMasterVO());
		return processActionPicDetail(mapping, formIn, request, response, errors);
	}
	
	public ActionForward processActionChildPicDetail(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {		
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		form.setItemMasterVos(form.getChildItemMasterVO());
		return processActionPicDetail(mapping, formIn, request, response, errors);
	}
	
	public ActionForward processActionPicDetail(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		HttpSession session = request.getSession(false);
		ActionForward actionForward = new ActionForward(mapping.getInput());

		String evtSrc = form.getPageEventSrc();
		
		ArrayList itemMasterVos = form.getItemMasterVos();
		ItemMasterVO itemMasterVO = new ItemMasterVO();		
		for(int i=0;itemMasterVos.size()>0 && i<itemMasterVos.size() 
				&& !evtSrc.equals(itemMasterVO.getItemId()); i++){				
			itemMasterVO = (ItemMasterVO)itemMasterVos.get(i);
		}		
		
		form.setCurrPicIdx(0);
		
		ItemMasterGroupCommonDelegate imDlg = new ItemMasterGroupCommonDelegate();
		ArrayList itemPicList = new ArrayList();
		try {
			itemPicList = imDlg.findByCriteria(new ItemMasterPicCriteria(itemMasterVO.getCompanyCode()
					   												   , itemMasterVO.getFabricCode()
					   												   , null));
		} catch (FindRecordException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		itemMasterVO.setItemPicVO(itemPicList);
		form.setItemMasterVO(itemMasterVO);
		
		
		form.setMainShowType(SHOW_ITEM_PIC_DETAIL);
		form.setPageEventSrc(null);
		return actionForward;
	}
	public ActionForward processActionShowPic(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		HttpSession session = request.getSession(false);
		ActionForward actionForward = new ActionForward(mapping.getInput());
		String imgFile;
		
		int idx = form.getCurrPicIdx();			
		ItemMasterPicVO itemPic = (ItemMasterPicVO)form.getItemMasterVO().getItemPicVO().get(idx);
		if(!CommonUtil.isEmpty(itemPic.getLv1Attachment()))	{
			Logger.log("itemPic lineno"+itemPic.getLineNo());
			FileOutputStream output = null;
			
			imgFile = "\\images\\catalogProductImages\\tmpFile.jpg";		
			
			File file=new File(request.getRealPath("/") + "\\images\\catalogProductImages\\tmpFile.jpg");        
			try {
				if(file.exists())			
					file.delete();
				
				file.createNewFile();
				
				output=new FileOutputStream(file,true);
				
				output.write(itemPic.getLv1Attachment());			
				output.close();		
				
			} catch (IOException e) {		
				e.printStackTrace();
			}	
	
			imgFile = "/images/catalogProductImages/tmpFile.jpg";
		}else{
			imgFile = ProjectConstants.DEFAULT_NO_FOUND_PRODUCT_IMAGE_PATH
				+ "/" + ProjectConstants.DEFAULT_NO_FOUND_PRODUCT_IMAGE_NAME;;
		}
		
		session.removeAttribute(ProjectConstants.SESSION_FLASH_MOVIE_PIC_PATH);
		session.setAttribute(ProjectConstants.SESSION_FLASH_MOVIE_PIC_PATH,imgFile);		
//			
//        session.removeAttribute(ProjectConstants.SESSION_FLASH_MOVIE_MAKSED);
//        session.setAttribute(ProjectConstants.SESSION_FLASH_MOVIE_MAKSED
//        					,CommonUtil.isEmpty(itemMasterVO.getWaterMark())?
//        							ProjectConstants.GENERIC_NO:ProjectConstants.GENERIC_YES);
	
		
		form.setMainShowType(SHOW_ITEM_PIC_DETAIL);
		form.setPageEventSrc(null);
		return actionForward;		
	}
	public ActionForward processActionSidebarExpand(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		CatalogLoginForm form = (CatalogLoginForm)formIn;
		HttpSession session = request.getSession(false);
		ActionForward actionForward = new ActionForward(mapping.getInput());
		
		String evtSrc = form.getPageEventSrc();	

		form.setPageEventSrc(null);		
		return actionForward;		
	}
	
	public ActionForward processActionItemSendEmail(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {		

        HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());
        CatalogLoginForm form = (CatalogLoginForm) formIn;
        User editingUser = (User) session.getAttribute(SimpleConstants.SESSION_USER);
        String action = form.getAction();
        ItemMasterVO item = form.getItemMasterVO();
        HashMap params = new HashMap();
        action = CommonUtil.isEmpty(action) ? "" : action.trim();       

        params.put(ProjectConstants.SESSION_PARAM_SEND_EMAIL_FROM, editingUser.getEmail());
        params.put(ProjectConstants.PARAM_SEND_EMAIL_WITH_SUBJECT, form.getSubject());
        params.put(ProjectConstants.PARAM_SEND_EMAIL_WITH_BODY, form.getBody());
        				// We willnot use this session now
        params.put(ProjectConstants.PARAM_SEND_EMAIL_BODY_1, item.getActicleNumber());
        params.put(ProjectConstants.PARAM_SEND_EMAIL_BODY_2, "http://" + request.getServerName()
		        + ":" + request.getServerPort()
		        + request.getContextPath() + "/"
		        + "catalogLogin.do?itmid=" + item.getItemId());
        params.put(ProjectConstants.SESSION_PARAM_SEND_EMAIL_SHOW_CC, ProjectConstants.GENERIC_NO);
        params.put(ProjectConstants.SESSION_PARAM_SEND_EMAIL_SHOW_BCC, ProjectConstants.GENERIC_NO);
        params.put(ProjectConstants.PARAM_SEND_EMAIL_WITH_VALUE
        		, ProjectConstants.SESSION_SEND_EMAIL_STATUS);

        if(!CommonUtil.isEmpty(session.getAttribute(ProjectConstants.SESSION_SEND_EMAIL_WITH_POPUP))){
        	session.removeAttribute(ProjectConstants.SESSION_SEND_EMAIL_WITH_POPUP);
        }
		session.setAttribute(ProjectConstants.SESSION_SEND_EMAIL_WITH_POPUP
				, ProjectConstants.GENERIC_YES);
        if(!CommonUtil.isEmpty(session.getAttribute(ProjectConstants.SESSION_PARAMA_SEND_EMAIL))){
        	session.removeAttribute(ProjectConstants.SESSION_PARAMA_SEND_EMAIL);
        }        
        session.setAttribute(ProjectConstants.SESSION_PARAMA_SEND_EMAIL, params);  
		
		form.setMainShowType(SHOW_ITEM_PIC_DETAIL);
		
        return actionForward;
    }

	public ActionForward processActionScrollLeft(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {	

        HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());
        CatalogLoginForm form = (CatalogLoginForm) formIn;
		
		form.setSidx(form.getSidx()-MAX_SHOW_PAGE);		
        return actionForward;
	}
	
	public ActionForward processActionScrollRight(ActionMapping mapping, ActionForm formIn, 
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {		

        ActionForward actionForward = new ActionForward(mapping.getInput());
        CatalogLoginForm form = (CatalogLoginForm) formIn;
		
		form.setSidx(form.getSidx()+MAX_SHOW_PAGE);		
        return actionForward;
	}
	public ActionForward processActionToPage(ActionMapping mapping, ActionForm formIn,
			HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {		

        ActionForward actionForward = new ActionForward(mapping.getInput());
        CatalogLoginForm form = (CatalogLoginForm) formIn;
        
        String evtSrc = form.getPageEventSrc();
        
		form.setSidx(Integer.parseInt(evtSrc)*MAX_SHOW_PAGE);	
		form.setPageEventSrc(null);
        return actionForward;
	}
	
	public ArrayList getItemList(ItemMasterCriteria criteria) throws FindRecordException{
		ArrayList itemList = new ArrayList();
		ArrayList itemDtlList = new ArrayList();
		ArrayList itemPicList = new ArrayList();
		
		
		String itemIds = "";
		ItemMasterGroupCommonDelegate imDlg = new ItemMasterGroupCommonDelegate();			
		
		itemList = imDlg.findByCriteria(criteria);
		for(int i=0; !CommonUtil.isEmpty(itemList) && i<itemList.size(); i++){
			ItemMasterVO vo = (ItemMasterVO)itemList.get(i);
			
			itemDtlList = new ArrayList();
			itemDtlList = imDlg.findByCriteria(new ItemMasterDtlCriteria(vo.getCompanyCode()
																	   , vo.getFabricCode()
																	   , criteria.getUserCode()));
//			itemPicList = new ArrayList();
//			itemPicList = imDlg.findByCriteria(new ItemMasterPicCriteria(vo.getCompanyCode()
//					   												   , vo.getFabricCode()
//					   												   , null));
			
			vo.setItemDtlVO(itemDtlList);
//			vo.setItemPicVO(itemPicList);
		}		
		return itemList;
	}	
	
	public ActionForward processActionTest(ActionMapping mapping, ActionForm formIn
			, HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
		
        HttpSession session = request.getSession(false);
        ActionForward actionForward = new ActionForward(mapping.getInput());
        CatalogLoginForm form = (CatalogLoginForm) formIn;       
        
        return actionForward;
	}
	protected ActionForward processActionSearch(ActionMapping mapping, ActionForm formIn
			, HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {
				return new ActionForward(mapping.getInput());		
	}
}
